package com.example.child_protection.service.impl;

import com.example.child_protection.dao.SystemFeedingProgramDao;
import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemFeedingProgramInsertRequestDTO;
import com.example.child_protection.dto.request.update.SystemFeedingProgramContentUpdateRequestDTO;
import com.example.child_protection.dto.request.update.SystemFeedingProgramUpdateRequestDTO;
import com.example.child_protection.enums.ServiceActionEnums;
import com.example.child_protection.model.SystemFeedingProgramModel;
import com.example.child_protection.service.SystemFeedingProgramManageService;
import com.example.child_protection.service.base.MyBaseService;
import com.example.child_protection.service.base.MyServiceExecutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 喂养方案管理service实现层
 * @date 2018-11-2
 * @author Biz
 */
@Component
public class SystemFeedingProgramManageServiceImpl extends MyBaseService implements SystemFeedingProgramManageService {

    @Autowired
    public SystemFeedingProgramDao systemFeedingProgramDao;

    /**
     * 添加
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO insert(SystemFeedingProgramInsertRequestDTO requestDTO){
        return this.service(ServiceActionEnums.SYSTEM_FEEDING_PROGRAM_INSERT,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SystemFeedingProgramInsertRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SystemFeedingProgramInsertRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemFeedingProgramModel model = new SystemFeedingProgramModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemFeedingProgramDao.insert(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 修改基本信息
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO update(SystemFeedingProgramUpdateRequestDTO requestDTO){
        return this.service(ServiceActionEnums.SYSTEM_FEEDING_PROGRAM_UPDATE,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SystemFeedingProgramUpdateRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SystemFeedingProgramUpdateRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemFeedingProgramModel model = new SystemFeedingProgramModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemFeedingProgramDao.updateSelective(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 修改内容
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO updateContent(SystemFeedingProgramContentUpdateRequestDTO requestDTO){
        return this.service(ServiceActionEnums.SYSTEM_FEEDING_PROGRAM_UPDATE_CONTENT,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SystemFeedingProgramContentUpdateRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SystemFeedingProgramContentUpdateRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemFeedingProgramModel model = new SystemFeedingProgramModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemFeedingProgramDao.updateSelective(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 删除
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO){
        return this.service (ServiceActionEnums.SYSTEM_FEEDING_PROGRAM_DELETE, requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SimpleIdRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SimpleIdRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemFeedingProgramModel model = new SystemFeedingProgramModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemFeedingProgramDao.deleteForLogic(model);
                res.setId(requestDTO.getId());
                res.successfully();
                return res;
            }
        });
    }

}
